package com.wally.auth.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSONObject;

public class AuthUtil {

	public static JSONObject doGetJson(String url) throws Exception {
		JSONObject jsonObject = null;
		String result = HttpClientUtil.httpGet(url);
		if (StringUtils.isNotBlank(result)) {
			jsonObject = JSONObject.parseObject(result);
		}
//		
//		CloseableHttpClient httpClient = HttpClients.createDefault();
//		HttpGet httpGet = new HttpGet(url);
//		CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
//		if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
//			HttpEntity entity = httpResponse.getEntity();
//			try {
//				String result = EntityUtils.toString(entity, Consts.UTF_8);
//				if (StringUtils.isNotBlank(result)) {
//					jsonObject = JSONObject.parseObject(result);
//				}
//			} catch (Exception e) {
//				e.printStackTrace();
//			} finally {
//				try {
//					if (null != httpGet) {
//						httpGet.releaseConnection();
//					}
//					if (null != httpResponse) {
//						httpResponse.close();
//						if (null != httpResponse) {
//							EntityUtils.consumeQuietly(httpResponse.getEntity());
//						}
//					}
//					if (null != httpClient) {
//						httpClient.close();
//					}
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		}
		return jsonObject;
	}

}
